import com.alibaba.fastjson.JSONObject;
import top.codedance.iotp.common.util.HexCodec;
import top.codedance.iotp.iot.sdk.DistributedHttpService;
import top.codedance.iotp.iot.sdk.IotService;
import top.codedance.iotp.iot.sdk.StandandService;
import top.codedance.iotp.iot.sdk.entity.DistributedRegistyUris;
import top.codedance.iotp.iot.sdk.po.sync.ComClientParam;
import top.codedance.iotp.iot.sdk.po.sync.ExecComParam;
import top.codedance.iotp.loadblance.entiy.RegistyUri;
import org.junit.Test;

//此测试用意是展示让标准SDK与分部式SDK调用共存的实现方法
public class StandandAndDistributedCoexistTestSdk {
    private HexCodec hc = new HexCodec();

    //其它协议与此处示例协议使用一样的方案即可
    @Test
    public void execCom(){
        boolean isDistributed = true;
        IotService service;
        if(isDistributed){
            DistributedRegistyUris distributedRegistyUris = new DistributedRegistyUris();
            RegistyUri registyUri1 = new RegistyUri("http://127.0.0.1:10015");
            distributedRegistyUris.add(registyUri1);
            service = DistributedHttpService.getInstance(distributedRegistyUris, "d3");
        } else {
            service = new StandandService("http://127.0.0.1:10012", "d3");
        }

        ExecComParam execComParam = new ExecComParam();
        execComParam.setUsername("u3");
        execComParam.setPassword("p3");
        ComClientParam comClientParam = new ComClientParam();
        comClientParam.setId(0);
        byte[] bytes = hc.toBytes("55AA010000");
        comClientParam.setCommand(bytes);

        execComParam.setClient(comClientParam);
        JSONObject jsonObject = service.execCom(execComParam);
        System.out.println(jsonObject.toJSONString());
    }
}
